home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 1963 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  2.2 KB

  1. Path: news.th-darmstadt.de!news!enno
  2. From: enno@inferenzsysteme.informatik.th-darmstadt.de (Enno Sandner)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Why use private class members instead of protected?
  5. Date: 14 Jan 1996 16:30:34 GMT
  6. Organization: Fachbereich Informatik, TH Darmstadt
  7. Distribution: world
  8. Message-ID: <ENNO.96Jan14173035@kitz.inferenzsysteme.informatik.th-darmstadt.de>
  9. References: <30F4AB49.6ABB@sierra.net>
  10.     <30F50874.15FB7483@intellektik.informatik.th-darmstadt.de>
  11.     <4d3q07$n8o@geraldo.cc.utexas.edu>
  12.     <30F61CAC.2781E494@intellektik.informatik.th-darmstadt.de>
  13.     <WIKMAN.96Jan14100533@falcon.research.nokia.com>
  14. NNTP-Posting-Host: kitz.intellektik.informatik.th-darmstadt.de
  15. In-reply-to: wikman@falcon.research.nokia.com's message of 14 Jan 1996 08:05:33 GMT
  16.  
  17. In article <WIKMAN.96Jan14100533@falcon.research.nokia.com> wikman@falcon.research.nokia.com (Johan Wikman) writes:
  18.  
  19.    In article <30F61CAC.2781E494@intellektik.informatik.th-darmstadt.de> Enno Sandner <enno@intellektik.informatik.th-darmstadt.de> writes:
  20.  
  21.       However an accessor/mutator pair like
  22.  
  23.               void MyClass :: set_data(const DataType&) { ... }
  24.               DataType MyClass :: get_data() const { return _data; }
  25.  
  26.       completely avoids this sort of problems. If the 'DataType' uses some 
  27.       technique to speed up copying (for example ref-counting) the overhead 
  28.       is minimal.
  29.  
  30.    I think you only change the problem into something else. Now if you
  31.    ever choose to change the representation of '_data' you face the
  32.    problem of converting a DataType to and from whatever type '_data'
  33.    is. The problem is still there, it has only changed shape.
  34.  
  35. Nevertheless it adds some sort of 'stability' to the class, because
  36. necessary conversions can performed without changing the interface.
  37. So, _if_ you need to access data-members of the base-classe(s) it's
  38. _often_ a better choice to use accessor/mutator pairs compared to
  39. making all data-members protected.
  40.  
  41.    In my opinion it fairly seldom makes sense to provide accessor/mutator
  42.    functions to the data members of a class. In fact, I get suspicious
  43.    when a class reminds you of a data repository instead of reminding you
  44.    of something that provides behaviour.
  45.  
  46. Agreed.
  47.  
  48.         Enno
  49.